<?php
namespace app\api\controller;

use app\BaseController;
use app\common\business\Sms as Busisms;
use think\facade\Log; // 引入日志

/**
 * 发送短信验证码
 */
class Sms extends BaseController{

	public function code(){
		$phoneNumber = input('param.phone_number');
		$data = [
			'phone_number'=>$phoneNumber,
		];
		//参数校验
		try{
			// Log::info('api-data:'.json_encode($data));
			validate(\app\api\validate\User::class)->scene('send_code')->check($data);
		}catch(\think\exception\ValidateException $e){
			Log::info('api-data:'.$e->getError());
			return show(config('status.error'),$e->getError());
		}

		// 调用业务逻辑层数据
		// 默认是调用ali,如果调用baidu等,需传参len,type
		$res = Busisms::sendCode($phoneNumber,4,"baidu");
		if($res){
			return show(config('status.success'),'发送短信验证码成功');
		}		
		return show(config('status.error'),'发送短信验证码失败');
	}
}